$(function () {
    
})


function getInitMenu() {
    $.ajax({
        url: "/init/getMenuByPageType",
        type: 'GET',
        dataType: "json",
        async: false,
        data: {
            pageType: '1'
        },
        success: function (data) {
            var html = '';
            html += '<li class="tab-select" data-menu-id="' + data[0].pageId + '" data-url="' + data[0].pageUrl + '">' + data[0].pageTitle + '</li>';
            for (var i = 1; i < data.length; i++) {
                html += '<li class="tab-no-select" data-menu-id="' + data[i].pageId + '" data-url="' + data[i].pageUrl + '">' + data[i].pageTitle + '</li>';
            }

            $('#firstMenu').html(html);

        }
    })}


//生成菜单树
    function createTree(parameters) {
        var menu_id = parameters.menu_id;
        var setting = {
            check: {
                enable: false
            },
            data: {
                key: {
                    name: "page_title"
                },
                simpleData: {
                    enable: true,
                    //chr_code
                    code: "page_id",
                    //当前节点id属性
                    idKey: "page_id",
                    //当前节点的父节点id属性
                    pIdKey: "parent_id",
                    rootPId: ""
                }
            },
            callback: {
                onClick: function (event, treeId, treeNode) {
                    // alert(treeNode.page_url + ", " + treeNode.page_id);
                    var url = treeNode.page_url;

                    if(url.indexOf('http://')==-1 ){
                        url='http://'+url;
                    }
                    window.open(url, 'newwindow', 'width=' + screen.width + ',height=' + screen.height + ', top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=n o, status=no');
                }

            },
            view: {showIcon: true}
        };

        var userId = antUtil.getSessionStorage('userId');
        var tokenId = antUtil.getSessionStorage('tokenId');

        switch (menu_id) {
            case 'home_page':
                createHomePageTree(setting, tokenId, userId);
                break;
            case 'AP_TYBB':
                createTIBBTree(setting, tokenId, userId);
                break;
            case 'AP_JX':
                createWZTree(setting, tokenId, userId);
                break;
            case 'AP_BMJS':
                createBMJSTree(setting, tokenId, userId);
                break;
            case 'AP_YS':
                createYSGLTree(setting, tokenId, userId);
                break;
            default:
                createHomePageTree(setting, tokenId, userId);
        }

    }
//生成预算管理菜单树
function createYSGLTree(setting, tokenId, userId) {

    var nd = antUtil.getSessionStorage('nd');

    $.ajax({
        url: "/menu/getMenuList",
        type: 'GET',
        dataType: "json",
        data: {
            url: 'http://192.168.0.19:7001/gfmis/services/PortalContentWebServiceImpl?wsdl',
            tokenId: tokenId,
            userId: userId,
            method: 'getMenuTree',
            nd: nd
        },
        success: function (data) {
            var zNodes = data;
            $.fn.zTree.init($("#menuTree"), setting, zNodes);

        }
    })

}
//生成闻政菜单树
    function createWZTree(setting, tokenId, userId) {

        var nd = antUtil.getSessionStorage('nd');

        $.ajax({
            url: "/menu/getMenuList",
            type: 'GET',
            dataType: "json",
            data: {
                url: 'http://192.168.0.89:7005/bappr/services/MenuForDivService?wsdl',
                tokenId: tokenId,
                userId: userId,
                method: 'getMenuTree',
                nd: nd
            },
            success: function (data) {
                var zNodes = data;
                $.fn.zTree.init($("#menuTree"), setting, zNodes);

            }
// 查看出错的状态信息
//             error: function (XMLHttpRequest, textStatus, errorThrown) {
//                 alert(XMLHttpRequest.status);
//                 alert(XMLHttpRequest.readyState);
//                 alert(textStatus);
//             }
        })

    }
//生成部门决算菜单树
function createBMJSTree(setting, tokenId, userId) {
    $.ajax({
        url: "/service/getOutService",
        type: 'GET',
        dataType: "json",
        data: {
            url: 'http://192.168.0.90:9797/menus?',
            tokenId: tokenId,
            userId: userId
        },
        success: function (data) {
            var zNodes = data;
            $.fn.zTree.init($("#menuTree"), setting, zNodes);

        }
    })

}

//生成统一报表菜单树
    function createTIBBTree(setting, tokenId, userId) {
        $.ajax({
            url: "/service/getOutService",
            type: 'GET',
            dataType: "json",
            data: {
                url: 'http://192.168.0.90:9797/menu?',
                tokenId: tokenId,
                userId: userId
            },
            success: function (data) {
                var zNodes = data;
                $.fn.zTree.init($("#menuTree"), setting, zNodes);

            }
        })

    }

    function createHomePageTree(setting, tokenId, userId) {
        var zNodes = [{
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "0",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "系统设置",
            "page_url": "http://www.baidu.com",
            "parent_id": "root"

        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "01",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "基本设置",
            "page_url": "http://www.baidu.com",
            "parent_id": "0"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "02",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "布局管理",
            "page_url": "http://www.baidu.com",
            "parent_id": "0"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "03",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "页面定制",
            "page_url": "http://www.baidu.com",
            "parent_id": "0"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "04",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "子菜单测试",
            "page_url": "http://www.baidu.com",
            "parent_id": "0"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "041",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "子菜单测试三级菜单",
            "page_url": "http://www.baidu.com",
            "parent_id": "04"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "0411",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "子菜单测试四级菜单",
            "page_url": "http://www.baidu.com",
            "parent_id": "041"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "1",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "内容管理",
            "page_url": "http://www.baidu.com",
            "parent_id": "root"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "11",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "文章管理",
            "page_url": "http://www.baidu.com",
            "parent_id": "1"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "12",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "链接管理",
            "page_url": "http://www.baidu.com",
            "parent_id": "1"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "13",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "快捷链接",
            "page_url": "http://www.baidu.com",
            "parent_id": "1"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "14",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "资源管理",
            "page_url": "http://www.baidu.com",
            "parent_id": "1"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "15",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "问卷管理",
            "page_url": "http://www.baidu.com",
            "parent_id": "1"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "2",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "系统集成",
            "page_url": "http://www.baidu.com",
            "parent_id": "root"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "21",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "待办集成",
            "page_url": "http://www.baidu.com",
            "parent_id": "2"
        }, {
            "is_high_perform": "N",
            "page_order": "0",
            "group_id": "admin",
            "is_display": "Y",
            "menu_orient": "1",
            "is_goto_edit": "N",
            "win_style": "height=600,width=950,resizable=false",
            "page_id": "22",
            "page_type": "3",
            "column_count": "2",
            "is_always_new": "Y",
            "page_title": "外部系统集成",
            "page_url": "http://www.baidu.com",
            "parent_id": "2"
        }];

        $.fn.zTree.init($("#menuTree"), setting, zNodes);
}
